package utils;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.TimeoutBean;

/**
 * Created by Administrator on 2018/8/8.
 */

public class TimeOutSortUtils {

    /**
     * 物品
     * @param list
     * @param flag
     */
    public static void sortTimeOutGoods(List<TimeoutBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getName(), o1.getName()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getName(), o1.getName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getName(), o1.getName()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getName(), o1.getName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 供应商
     * @param list
     * @param flag
     */
    public static void sortTimeOutSupplier(List<TimeoutBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufactor(), o1.getManufactor()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufactor(), o1.getManufactor()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufactor(), o1.getManufactor()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufactor(), o1.getManufactor()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 过期时间
     * @param list
     * @param flag
     */
    public static void sortTimeOut(List<TimeoutBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    long time1 = Long.parseLong(TimeUtil.dateToStamp(o1.getTimeoutDate()));
                    long time2 = Long.parseLong(TimeUtil.dateToStamp(o2.getTimeoutDate()));
                    if (time2 - time1 < 0) {
                        return 1;
                    } else if (time2 - time1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    long time1 = Long.parseLong(TimeUtil.dateToStamp(o1.getTimeoutDate()));
                    long time2 = Long.parseLong(TimeUtil.dateToStamp(o2.getTimeoutDate()));
                    if (time2 - time1 > 0) {
                        return 1;
                    } else if (time2 - time1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 柜子
     * @param list
     * @param flag
     */
    public static void sortTimeOutCabinet(List<TimeoutBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    if (Integer.parseInt(o2.getCabinetCode()) - Integer.parseInt(o1.getCabinetCode()) < 0) {
                        return 1;
                    } else if (Integer.parseInt(o2.getCabinetCode()) - Integer.parseInt(o1.getCabinetCode()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    if (Integer.parseInt(o2.getCabinetCode()) - Integer.parseInt(o1.getCabinetCode()) > 0) {
                        return 1;
                    } else if (Integer.parseInt(o2.getCabinetCode()) - Integer.parseInt(o1.getCabinetCode()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 规格
     * @param list
     * @param flag
     */

    public static void sortTimeOutSpecification(List<TimeoutBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 数量
     * @param list
     * @param flag
     */
    public static void sortTimeOutNumber(List<TimeoutBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    if (o2.getNumber() - o1.getNumber() > 0) {
                        return 1;
                    } else if (o2.getNumber() - o1.getNumber() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<TimeoutBean>() {
                @Override
                public int compare(TimeoutBean o1, TimeoutBean o2) {
                    if (o2.getNumber() - o1.getNumber() < 0) {
                        return 1;
                    } else if (o2.getNumber() - o1.getNumber() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
}
